package com.example.goodsass.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.goodsass.dto.ArticleInfoSelAllDto;
import com.example.goodsass.mapper.ArticleInfoMapper;
import com.example.goodsass.domain.ArticleInfo;
import com.example.goodsass.mapper.TagArticleMapper;
import com.example.goodsass.service.ArticleInfoService;
import com.example.goodsass.vo.ArticleInfoVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章信息表(ArticleInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-04-08 20:16:55
 */
@Service("articleInfoService")
public class ArticleInfoServiceImpl extends ServiceImpl<ArticleInfoMapper, ArticleInfo> implements ArticleInfoService {
    @Resource
    ArticleInfoMapper articleInfoMapper;

    @Resource
    TagArticleMapper tagArticleMapper;

    @Override
    public List<ArticleInfoVo> selectAllByPage(ArticleInfoSelAllDto articleInfo) {
        ArrayList<ArticleInfoVo> articleInfoVos = new ArrayList<>();
        articleInfo.sum();
        List<ArticleInfo> articleInfos = articleInfoMapper.selectAllByPage(articleInfo);
        for (ArticleInfo info : articleInfos) {
            ArticleInfoVo articleInfoVo = BeanUtil.copyProperties(info, ArticleInfoVo.class);
            List<String> tagArticles = tagArticleMapper.selectTagsByArticleId(info.getArticleId());
            articleInfoVo.setArticleTag(tagArticles);
            articleInfoVos.add(articleInfoVo);
        }
        return articleInfoVos;
    }
}

